import { Global, Module } from '@nestjs/common'
import { MongooseModule } from '@nestjs/mongoose'
import { ProjectSchema } from './schema/project.schema'
import { UserSchema } from './schema/user.schema'

const MONGO_MODULES = MongooseModule.forFeature([
    {
        name: 'USER_MODEL',
        schema: UserSchema,
        collection: 'user'
    },
    {
        name: 'PROJECT_MODEL',
        schema: ProjectSchema,
        collection: 'project'
    }
])

@Global()
@Module({
    imports: [
        MongooseModule.forRoot('mongodb://localhost:27017/xz_management', {
            useNewUrlParser: true,
            useUnifiedTopology: true,
            useCreateIndex: true,
            useFindAndModify: false,
        }),
        MONGO_MODULES
    ],
    exports: [
        MONGO_MODULES
    ]
})
export class DbModule { }
